package com.cskaoyan.mall.listenser;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @PackgeName: com.cskaoyan.mall.listenser
 * @ClassName: ApplicationListener
 * @Author: admin
 * Date: 2020/5/4 14:49
 * project name: Javaproject1
 * @Version:
 * @Description:
 */


@WebListener
public class ApplicationListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {

        //???
        InputStream inputStream = ApplicationListener.class.getClassLoader().getResourceAsStream("application.properties");
        Properties properties = new Properties();
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }


        String domain = properties.getProperty("domain");
        servletContextEvent.getServletContext().setAttribute("domain", domain);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
